package top.dingyingying.study.javawebjdbc.dao;

import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBHelper {
//数据库连接url
    public static final String URL =
            "jdbc:mysql://teach_mysql.huhuiyu.top:31000/db_dingyingying?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai";
//数据库名称
    public static  final String USER = "db_dingyingying";
//数据库密码
    public static final String PASSWORD = "dyy1787368066";
//数据库驱动类名称
   public static final String DRIVER = "com.mysql.cj.jdbc.Driver";

   static {
//       加载驱动程序
       try {
           Class.forName(DRIVER);
       } catch (ClassNotFoundException e) {
           throw new RuntimeException(e);
       }
   }

//    获取数据库连接
    public static Connection getConnertion() {
        try {
            return DriverManager.getConnection(URL, USER, PASSWORD);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }



}
